/**
 * 
 */
package com.orange.controller;

import java.io.File;
import java.io.FileInputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.orange.dbhelp.page.Page;
import com.orange.handler.AuthExpertService;
import com.orange.handler.AuthExportGroupMapService;
import com.orange.handler.AuthOrgUserService;
import com.orange.handler.AuthSchoolService;
import com.orange.handler.AuthSysValueService;
import com.orange.handler.manage.AuthSysDownloadService;
import com.orange.modules.bean.SessionUser;
import com.orange.modules.entity.AuthSysValue;
import com.orange.modules.entity.expert.AuthExpert;
import com.orange.modules.entity.expert.AuthExportGroupMap;
import com.orange.modules.entity.manage.AuthOrgUser;
import com.orange.modules.entity.manage.AuthSysDownload;
import com.orange.modules.entity.school.AuthSchool;
import com.orange.util.AppConfig;
import com.orange.util.Hash;
import com.orange.util.ReturnCode;

/**
 * @author gaogs
 *
 * 2016-7-19
 */
@Controller
@RequestMapping(value="/sys")
public class ServiceController extends BaseController{
	
	private Logger logger = Logger.getLogger( ServiceController.class ) ;
	
	@Autowired
	private AuthSchoolService authSchoolService;
	
	@Autowired
	private AuthSysValueService authSysValueService;
	
	@Autowired
	private AppConfig appConfig;
	
	@Autowired
	private AuthOrgUserService authOrgUserService;
	
	@Autowired
	private AuthExpertService authExpertService;
	
	@Autowired
	private AuthExportGroupMapService authExportGroupMapService;
	
	@Autowired
	private AuthSysDownloadService authSysDownloadService;
	
	/**
	 * 学校登录
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/schoolLogin" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> login(HttpServletRequest request,
										HttpServletResponse response ,
										@RequestBody Map<String ,String> map
			){
		try {
			String account=map.get("account");
			if(StringUtils.isBlank(account)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"account不可为空");
			}
			String password=map.get("password");
			if(StringUtils.isBlank(password)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"password不可为空");
			}
			String major = map.get("major");
			if(StringUtils.isBlank(major)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"专业不可为空");
			}
			AuthSysValue asv = authSysValueService.getSysValue("11001"); //认证节点设置
			AuthSysValue asv1 = authSysValueService.getSysValue("11002"); //专业
			if(asv==null)
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"当前不是申报阶段");
			else{
				if(!"1001".equals(asv.getSysvalue()))
					return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"当前不是申报阶段");
			}
			if(asv1==null)
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"当前专业目前无法申报");
			else{
				if(!asv1.getSysvalue().equals(major))
					return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"当前专业目前无法申报");
			}
			AuthSchool a=authSchoolService.queryAuthSchoolInfoByAccount(map.get("account"),major);
			if(null==a){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户名或密码错误");
			}
			String newPassw=Hash.sha2InHex(password);
			if(!newPassw.equals(a.getPassword())){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户名或密码错误");
			}
			if("2".equals(major)){ //0：学前教育  1：小学教育 2：中学教育
				String status = map.get("status");
				if(StringUtils.isBlank(status)){
					return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"中学分类不能为空");
				}
				request.getSession().setAttribute(SessionUser.SESSION_STATUS, status);//1101：理科    1102：文科     1103：整体申报
			}
			request.getSession().setAttribute(SessionUser.SESSION_USER_TYPE, "0");
			request.getSession().setAttribute(SessionUser.SESSION_USER_KEY, a.getPid());
			request.getSession().setMaxInactiveInterval(1800);
			
			Map<String,String> m=new HashMap<String, String>();
			m.put("userId", a.getPid());
			m.put("userType", "0");//学校
			m.put("schoolName", a.getSchoolName());//学校名字
			m.put("account", a.getAccount());//现场代码
			m.put("major", a.getMajor());//学校专业
			m.put("status", map.get("status"));//学科   1101：理科    1102：文科     1103：整体申报
			return toResponse(m,ReturnCode.SUCCESS,"登录验证成功");
		} catch (Exception e) {
			logger.error("登录异常", e);
			return toResponse(null,ReturnCode.FAIL,"登录异常");
		}
	}
	
	/**
	 * 管理员登录
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/adminLogin" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> adminLogin(HttpServletRequest request,
										HttpServletResponse response ,
										@RequestBody Map<String ,String> map
			){
		try {
			String account=map.get("account");
			if(StringUtils.isBlank(account)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"account不可为空");
			}
			String password=map.get("password");
			if(StringUtils.isBlank(password)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"password不可为空");
			}
			AuthOrgUser s=authOrgUserService.getAuthOrgUserByAccount(account,"4");
			if(null==s){
				return toResponse(null,ReturnCode.USERINFO_NOT_EXIST,"管理员信息不存在");
			}
			String newPassw=Hash.sha2InHex(password);
			if(!newPassw.equals(s.getPassword())){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"密码错误");
			}
			Map<String,String> m=new HashMap<String, String>();
			m.put("userId", s.getPid());
			m.put("account", s.getUserAccount());//
			if("1".equals(s.getType())){
				m.put("userType", "3");
			}else{
				m.put("userType", "4");
			}
			request.getSession().setAttribute(SessionUser.SESSION_USER_TYPE, "3");//管理员
			request.getSession().setAttribute(SessionUser.SESSION_USER_KEY, s.getPid());
			request.getSession().setMaxInactiveInterval(1800);
			
			return toResponse(m,ReturnCode.SUCCESS,"登录验证成功");
		} catch (Exception e) {
			logger.error("登录异常", e);
			return toResponse(null,ReturnCode.FAIL,"登录异常");
		}
	}
	
	/**
	 * 专家用户登录
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/expertLogin_review" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> exportLogin(HttpServletRequest request,HttpServletResponse response ,
										@RequestBody Map<String ,String> map
			){
		try {
			String account=map.get("account");
			if(StringUtils.isBlank(account)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"account不可为空");
			}
			String password=map.get("password");
			if(StringUtils.isBlank(password)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"password不可为空");
			}
			AuthExpert ae = authExpertService.queryExpertByAccount(account);
			if(null==ae){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户名或密码错误");
			}
			String newPassw=Hash.sha2InHex(password);
			if(!newPassw.equals(ae.getPassword())){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户名或密码错误");
			}
			AuthSysValue asv = authSysValueService.getSysValue("11001"); 
			if(!"1003".equals(asv.getSysvalue())){
				return toResponse(null,ReturnCode.AUTH_PHASE_IS_FALSE,"当前非现场考察阶段");
			}
			AuthExportGroupMap a=authExportGroupMapService.queryAuthExportGroupMapByExpertId(ae.getPid());
			if(null==a){
				return toResponse(null,ReturnCode.USER_IDENTITY_NOT_MATCH,"非现场考察专家不可登录该系统");
			}
			
			request.getSession().setAttribute(SessionUser.SESSION_USER_TYPE, "2");//现场考察专家组成员
			request.getSession().setAttribute(SessionUser.SESSION_USER_KEY, ae.getPid());
			request.getSession().setMaxInactiveInterval(1800);
			
			Map<String,String> m=new HashMap<String, String>();
			m.put("userId", ae.getPid());
			m.put("userType", "2");//现场考察专家
			m.put("expertName", ae.getExpertname());//现场考察名字
			m.put("account", ae.getExpertcode());//现场考察账号
			m.put("identity", a.getIdentitys());//0：组员   1：副组长  2：组长 3：联络员
			
			return toResponse(m,ReturnCode.SUCCESS,"登录验证成功");
		} catch (Exception e) {
			logger.error("登录异常", e);
			return toResponse(null,ReturnCode.FAIL,"登录异常");
		}
	}
	
	
	/**
	 * 材料评审专家登录
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/expertLogin_material" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> expertLogin_material(HttpServletRequest request,HttpServletResponse response ,
										@RequestBody Map<String ,String> map
			){
		try {
			String account=map.get("account");
			if(StringUtils.isBlank(account)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"account不可为空");
			}
			String password=map.get("password");
			if(StringUtils.isBlank(password)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"password不可为空");
			}
			AuthExpert ae = authExpertService.queryExpertByAccount(account);
			if(null==ae){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户名或密码错误");
			}
			String newPassw=Hash.sha2InHex(password);
			if(!newPassw.equals(ae.getPassword())){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户名或密码错误");
			}
			AuthSysValue asv = authSysValueService.getSysValue("11001"); 
			if(!"1002".equals(asv.getSysvalue())){
				return toResponse(null,ReturnCode.AUTH_PHASE_IS_FALSE,"当前非材料评审阶段");
			}
			AuthExportGroupMap a=authExportGroupMapService.queryAuthExportGroupMapByExpertId1(ae.getPid());
			if(null==a){
				return toResponse(null,ReturnCode.USER_IDENTITY_NOT_MATCH,"非材料评审专家不可登录该系统");
			}
			
			request.getSession().setAttribute(SessionUser.SESSION_USER_TYPE, "1");//材料评审成员
			request.getSession().setAttribute(SessionUser.SESSION_USER_KEY, ae.getPid());
			request.getSession().setMaxInactiveInterval(1800);
			
			Map<String,String> m=new HashMap<String, String>();
			m.put("userId", ae.getPid());
			m.put("userType", "1");//材料评审专家
			m.put("expertName", ae.getExpertname());//材料评审名字
			m.put("account", ae.getExpertcode());//材料评审账号
			m.put("identity", a.getIdentitys());//0：组员   1：副组长  2：组长 3：联络员
			return toResponse(m,ReturnCode.SUCCESS,"登录验证成功");
		} catch (Exception e) {
			logger.error("登录异常", e);
			return toResponse(null,ReturnCode.FAIL,"登录异常");
		}
	}
	
	
	/**
	 * 修改密码
	 * @param request
	 * @param response
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/updatePass" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> updatePass(HttpServletRequest request,HttpServletResponse response ,@RequestBody Map<String ,String> map){
		
		try {
			String pid=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
			if(null==pid){
				return toResponse(null,ReturnCode.NOLOGIN,"未登录");
			}
			
			String type=map.get("type");
			if(StringUtils.isBlank(type)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"类型不可为空");
			}
			
			String password=map.get("oldpassword");
			if(StringUtils.isBlank(password)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"原密码不可为空");
			}
			String newpass1 = map.get("newpassword1");
			if(StringUtils.isBlank(newpass1)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"新密码不可为空");
			}
			String newpass2 = map.get("newpassword2");
			if(StringUtils.isBlank(newpass2)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"新密码不可为空");
			}
			if(!newpass1.equals(newpass2)){
				return toResponse(null,ReturnCode.PASSWOED_IS_FALSE,"两次密码不一致");
			}
			String newpass = map.get("newpassword1");
			
			if("0".equals(type)){//修改机构密码
				String account=map.get("account");
				if(StringUtils.isBlank(account)){
					return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"账户名不可为空");
				}
				AuthSchool a = authSchoolService.queryAuthSchoolInfoByAccount(account);
				if(null==a){
					return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户名或密码错误");
				}
				String newPassw=Hash.sha2InHex(password);
				if(!newPassw.equals(a.getPassword())){
					return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"原密码错误");
				}
				String newp = Hash.sha2InHex(newpass);
				a.setPassword(newp);
				authSchoolService.updateAuthSchoolInfo(a);
			}else if("1".equals(type)){//专家修改密码
				String account=map.get("account");
				if(StringUtils.isBlank(account)){
					return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"账户名不可为空");
				}
				AuthExpert a=authExpertService.queryExpertByAccount(account);
				if(null==a){
					return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户信息不存在");
				}
				String newPassw=Hash.sha2InHex(password);
				if(!newPassw.equals(a.getPassword())){
					return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"原密码错误");
				}
				String newp = Hash.sha2InHex(newpass);
				a.setPassword(newp);
				authExpertService.updateAuthExpert(a);
			}else {
				AuthOrgUser a=authOrgUserService.queryAuthOrgUserById(pid);
				if(null==a){
					return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"用户信息不存在");
				}
				String newPassw=Hash.sha2InHex(password);
				if(!newPassw.equals(a.getPassword())){
					return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"原密码错误");
				}
				String newp = Hash.sha2InHex(newpass);
				a.setPassword(newp);
				authOrgUserService.saveAuthOrgUserInfo(a);
			}
			
			return toResponse(null,ReturnCode.SUCCESS,"密码修改成功");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null,ReturnCode.SUCCESS,"密码修改失败");
		}
		
	}
	
	public static void main(String[] args) {
		String str="zdxh/aserg/aweryaserh/sss.doc";
		System.out.println(str.substring(str.lastIndexOf("/")+1, str.length()));
	}
	
	/**
	 * 试题上传
	 * @param Filedata
	 * @return
	 */
	@RequestMapping(value="/uploadfile" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> uploadFile(
			@RequestParam("file")MultipartFile filedata
			){
		try {
			String returnDatasUrl = null;
	  		String datasfile = appConfig.getFilePath();
	  		
	  		//取得可上传的文件类型  
	  		List<String>fileTypes = arrayToList(appConfig.getFileType().split(","));
	  		
	  		String fileName = filedata.getOriginalFilename();  
	  		//获取上传文件类型的扩展名,先得到.的位置，再截取从.的下一个位置到文件的最后，最后得到扩展名  
	  		String ext = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());  
	  		//对扩展名进行小写转换  
	  		ext = ext.toLowerCase();  
	  		/*//新的文件名
	  		String newFileName = new SimpleDateFormat("yyyyMMddHHmmssms").format(new Date()) + 
	  				(int)(Math.random()*10000) + "." + ext;*/
	  		File file = null;
	  		if(!fileTypes.contains(ext)){
	  			return toResponse(null,ReturnCode.FILE_TYPE_NOT_MATCH,"该文件类型不允许");
	  		}
	  		Long examSize=filedata.getSize();
	  		if(1.0*examSize/1024/1024>appConfig.getFileSize()){
	  			return toResponse(null,ReturnCode.FILE_SIZE_TOO_LONG,"文件大小超出限定上限");
	  		}
	  		
	  		Calendar cal=Calendar.getInstance();
            int y=cal.get(Calendar.YEAR);
            int m=cal.get(Calendar.MONTH)+1;
            int d=cal.get(Calendar.DATE);
            Long nowTime=new Date().getTime();
            String pathbig=datasfile+y+"/"+m+"/"+d+"/"+nowTime+"/"+fileName;
            file=new File(pathbig);
     		if(!file.exists()){
     			file.getParentFile().mkdirs();
     			file.createNewFile();
     		}
     		filedata.transferTo(file);
				
		    returnDatasUrl =y+"/"+m+"/"+d+"/"+nowTime+"/"+fileName;
			return toResponse(returnDatasUrl,ReturnCode.SUCCESS,null);
		} catch (Exception e) {
			logger.error("文件上传失败", e);
			return toResponse(null,ReturnCode.FAIL,"文件上传失败");
		}
	}
	
	   private List<String> arrayToList(String[] strs){
	    	List<String> list=new ArrayList<String>();
	    	if(strs.length>0){
	    		for(int a =0;a<strs.length;a++){
	    			list.add(strs[a].toString().trim());
	    		}
	    	}
			return list;
	    	
	    }
	   
	
	/**
	 * 清除所有session
	 * @param request
	 * @param response
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/removeSession" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> removeSession(HttpServletRequest request,HttpServletResponse response ,@RequestBody Map<String ,String> map){
		request.getSession().invalidate();
		return toResponse(null,ReturnCode.SUCCESS,"session清除成功!");
	}
	
	/**
	 * 0:评估公告  1：下载中心  2：政策法规    分页查询
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryAuthSysDownloadInfoPage" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryAuthSysDownloadInfoPage(HttpServletRequest request,@RequestBody Map<String,String> map) throws SQLException{
		
		try{
			String type=map.get("type");
			String pageSize=map.get("pageSize");
			String pageNumber=map.get("pageNumber");
			if(StringUtils.isBlank(pageSize)||StringUtils.isBlank(pageNumber)){
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "参数不可为空");
			}
			Page<AuthSysDownload> page=authSysDownloadService.queryAuthSysDownloadInfoPage(map);
			return toResponse(page, ReturnCode.SUCCESS, "分页查询成功");
		}catch(Exception e){
			logger.info("分页查询失败", e);
			return toResponse(null,ReturnCode.FAIL,"分页查询失败");
		}
	}
	
	/**
	 * 下载文档
	 * @param request
	 * @param response
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/downloadFile" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public void downloadFile(HttpServletRequest request,HttpServletResponse response ,@RequestParam String pid){
		
		try {
			AuthSysDownload a=authSysDownloadService.queryAuthSysDownloadById(pid);
			if(null==a){
				return;
			}
			//获取网站部署路径(通过ServletContext对象)，用于确定下载文件位置，从而实现下载  
	        String path = appConfig.getFilePath();  
	        //1.设置文件ContentType类型，这样设置，会自动判断下载文件类型  
	        response.setContentType("multipart/form-data");  
	        //2.设置文件头：最后一个参数是设置下载文件名(假如我们叫a.pdf) 
	        String filepath= a.getFileUrl();
	        String filename=filepath.substring(filepath.lastIndexOf("/")+1, filepath.length());
	        response.setHeader("Content-Disposition", "inline; filename="  
	                + new String(filename.getBytes("utf-8"), "ISO-8859-1"));  
	        ServletOutputStream out;  
	        //通过文件路径获得File对象(假如此路径中有一个download.pdf文件)  
	        File file = new File(path +filepath);  
	  
	            FileInputStream inputStream = new FileInputStream(file);  
	  
	            //3.通过response获取ServletOutputStream对象(out)  
	            out = response.getOutputStream();  
	            
	            byte[] buffer = new byte[512];  
	            int count = 0;
		         while ((count = inputStream.read(buffer)) > 0) {
		        	 out.write(buffer, 0, count);
		         }
	            inputStream.close();  
	            out.close();  
	            out.flush();  
	  
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 领导查看登录
	 */
	@RequestMapping(value="/leaderLogin" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> leaderLogin(HttpServletRequest request,HttpServletResponse response ,@RequestBody Map<String ,String> map){
		try {
			String account=map.get("account");
			if(StringUtils.isBlank(account)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"account不可为空");
			}
			String password=map.get("password");
			if(StringUtils.isBlank(password)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"password不可为空");
			}
			AuthOrgUser s=authOrgUserService.getAuthOrgUserByAccount(account,"5");
			if(null==s){
				return toResponse(null,ReturnCode.USERINFO_NOT_EXIST,"管理员信息不存在");
			}
			String newPassw=Hash.sha2InHex(password);
			if(!newPassw.equals(s.getPassword())){
				return toResponse(null,ReturnCode.USERNAME_OR_PASSWORD_FALSE,"密码错误");
			}
			Map<String,String> m=new HashMap<String, String>();
			m.put("userId", s.getPid());
			m.put("account", s.getUserAccount());//
			
			m.put("userType", "5");
			
			request.getSession().setAttribute(SessionUser.SESSION_USER_TYPE, "5");//领导
			request.getSession().setAttribute(SessionUser.SESSION_USER_KEY, s.getPid());
			request.getSession().setMaxInactiveInterval(1800);
			
			return toResponse(m,ReturnCode.SUCCESS,"登录验证成功");
		} catch (Exception e) {
			logger.error("登录异常", e);
			return toResponse(null,ReturnCode.FAIL,"登录异常");
		}
	}
}
